package com.me.blood.activity;

import android.view.View;
import android.view.ViewGroup;

import com.me.ad.ADType;
import com.me.bean.Ad;
import com.me.blood.App;
import com.me.blood.frag.BaseDialogFragment;
import com.me.blood.frag.TipDlg;
import com.me.utils.Constant;
import com.me.utils.Utils;
import com.toutiao.base.BaseAdActivity;

public abstract class BaseActivity extends BaseAdActivity {

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        if (paddingTop()) {
            view.setPadding(0, Utils.getStatusBarHeight(this), 0, 0);
        }
    }

    @Override
    protected void loadXp() {
        super.loadXp(new Ad(App.getApp().getAdBean().interstitialId, getXpType()));
    }

    protected abstract ADType getXpType();

    @Override
    protected void loadAd() {
        if (!App.getApp().isEnable(getXpType())) {
            return;
        }
        super.loadAd();
    }

    protected boolean paddingTop() {
        return true;
    }

    public void getReward(ADType type, Runnable runnable) {
        if (!App.getApp().isEnable(type)) {
            if (runnable != null) {
                runnable.run();
            }
            return;
        }
        if (!Constant.tip) {
            TipDlg dlg = new TipDlg();
            dlg.setOnDismissListener(new BaseDialogFragment.OnDismissListener() {
                @Override
                public void onDismiss(boolean isOk, Object value) {
                    if (isOk) {
                        Constant.tip = true;
                        getRewardAd(type, runnable);
                    }
                }
            });
            dlg.show(getSupportFragmentManager(), "tip2");
        } else {
            getRewardAd(type, runnable);
        }
    }

    private void getRewardAd(ADType type, Runnable runnable) {
        super.getRewardAd(new Ad(App.getApp().getAdBean().rewardId, type), runnable);
    }

    public void getFeed(ViewGroup group, int w) {
        if (!App.getApp().isEnable(ADType.FEED)) {
            return;
        }
        super.getFeed(new Ad(App.getApp().getAdBean().nativeId, w, ADType.FEED), group);
    }
}
